package com.woniu.cloud.storeassembly.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.cloud.common.dto.Result;
import com.woniu.cloud.entity.TStoreRevenue;

import com.woniu.cloud.form.StoreRevenueSelectForm;
import com.woniu.cloud.storeassembly.mapper.TStoreRevenueMapper;
import com.woniu.cloud.storeassembly.service.ITStoreRevenueService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * <p>
 * 门店流水表 服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2021-09-29
 */
@Service
public class TStoreRevenueServiceImpl extends ServiceImpl<TStoreRevenueMapper, TStoreRevenue> implements ITStoreRevenueService {


    @Resource
    private TStoreRevenueMapper storeRevenueMapper;


    @Override
    public Result insertStoreRevenue(TStoreRevenue storeRevenue) {

        int insert = storeRevenueMapper.insert(storeRevenue);
        if (0!=insert) {
            return Result.success("添加成功",null);

        }
        return Result.fail("添加失败",null);
    }

    @Override
    public Result getStoreRevenue(StoreRevenueSelectForm storeRevenue) {
        SimpleDateFormat sformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//日期格式
        QueryWrapper<TStoreRevenue> wrapper = new QueryWrapper<>();

        wrapper.eq(null!=storeRevenue.getStoreRevenueId(),"store_revenue_id",storeRevenue.getStoreRevenueId())
                .eq(null!=storeRevenue.getStoreRevenueStoreId(),"store_revenue_store_id",storeRevenue.getStoreRevenueStoreId())
                .eq(null!=storeRevenue.getStoreRevenuePrice(),"store_revenue_price",storeRevenue.getStoreRevenuePrice())
                .eq(null!=storeRevenue.getStoreRevenueStorePurchaseOrderId(),"store_revenue_store_purchase_order_id",storeRevenue.getStoreRevenueStorePurchaseOrderId())
                .eq(null!=storeRevenue.getStoreRevenueServiceOrderId(),"store_revenue_service_order_id",storeRevenue.getStoreRevenueServiceOrderId())
                .eq(null!=storeRevenue.getStoreRevenueStoreGoodOrderId(),"store_revenue_store_good_order_id",storeRevenue.getStoreRevenueStoreGoodOrderId())
                .eq(null!=storeRevenue.getStoreRevenueType(),"store_revenue_type",storeRevenue.getStoreRevenueType())
                .eq(null!=storeRevenue.getStoreRevenueRetype(),"store_revenue_retype",storeRevenue.getStoreRevenueRetype())
                .ge(null!=storeRevenue.getTimeAfter(),"row_add_time",storeRevenue.getTimeAfter())
                .le(null!=storeRevenue.getTimeBefore(),"row_add_time",storeRevenue.getTimeBefore());
        Integer index = storeRevenue.getPageIndex();
        IPage<TStoreRevenue> page = new Page<>(null==index?1:index,8);
        IPage<TStoreRevenue> storeRevenueIPage = storeRevenueMapper.selectPage(page, wrapper);
        if (0!=storeRevenueIPage.getRecords().size()) {
            return Result.success("查询成功",storeRevenueIPage);

        }
        return Result.fail("查询失败",null);

    }
}
